home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 14389 / 14389.xpi / chrome / content / imgurSearch.js next >
Text File  |  2010-01-25  |  2KB  |  63 lines

  1. if(!com) var com = {};
  2. if(!com.imgur) com.imgur = {};
  3. if(!com.imgur.imgur_fox) com.imgur.imgur_fox = {};
  4.  
  5. com.imgur.imgur_fox = {
  6.  
  7.     imgur_URL: "http://imgur.com",
  8.     targetURL: '',
  9.  
  10.     showImageContext: function() {
  11.         var imgur_fox = com.imgur.imgur_fox;
  12.  
  13.         document.getElementById("context-imgur-search").hidden = true;
  14.  
  15.         if(gContextMenu.onImage) {
  16.             imgur_fox.targetURL = gContextMenu.mediaURL;
  17.             // For versions of Firefox < 3.1
  18.             if(!imgur_fox.targetURL) {
  19.                 imgur_fox.targetURL = gContextMenu.imageURL;
  20.             }
  21.             document.getElementById("context-imgur-search").hidden = false;
  22.         }
  23.     },
  24.  
  25.     showImageInit: function() {
  26.         var menu = document.getElementById("contentAreaContextMenu");
  27.         menu.addEventListener("popupshowing", com.imgur.imgur_fox.showImageContext, false);
  28.     },
  29.  
  30.     loadxml: function (location) {
  31.       xhttp=new XMLHttpRequest();
  32.       xhttp.open("GET",location,false);
  33.       xhttp.send(null);
  34.       xmlDoc=xhttp.responseXML; 
  35.       
  36.       var new_image_url = xmlDoc.getElementsByTagName("original_image")[0].childNodes[0].nodeValue;
  37.       var full_url = xmlDoc.getElementsByTagName("imgur_page")[0].childNodes[0].nodeValue;
  38.       
  39.       //open new tab and when finished loading copy url to clipboard
  40.       var newTab = gBrowser.getBrowserForTab(gBrowser.addTab(full_url));
  41.       
  42.       const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);  
  43.       gClipboardHelper.copyString(new_image_url); 
  44.       
  45.     },
  46.  
  47.     imgurSearch: function() {
  48.         var imgur_fox = com.imgur.imgur_fox;
  49.         var api_key = 'e1eec71d1a2ac1ad84fd93e301b1ed6c';
  50.         var uploadURL = 'http://imgur.com/api/upload.xml';
  51.     
  52.         if(!imgur_fox.targetURL) return;
  53.         var location = uploadURL + '?key=' + encodeURIComponent(api_key) + '&image=' + encodeURIComponent(imgur_fox.targetURL);
  54.         
  55.         imgur_fox.loadxml(location);
  56.         imgur_fox.targetURL = ''; // Reset
  57.  
  58.     }
  59.  
  60. }
  61.  
  62. window.addEventListener("load", com.imgur.imgur_fox.showImageInit, false);
  63.